package org.example.service;

import org.example.dto.ShanjiaZhxg;
import org.example.mapper.Kaidianmapper;
import org.example.mapper.Shanjiamapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Objects;

@Service
public class KaidianService {
    @Autowired
    Kaidianmapper kaidianmapper;
    @Autowired
    Shanjiamapper shanjiamapper;

    /**
     * 新增开店
     *
     * @param yonghu
     * @param dianpu
     */
    public void xz(String yonghu, String dianpu) {
        String username = kaidianmapper.cx(yonghu);
        if (Objects.equals(username, "") || username == null) {
            kaidianmapper.xz(yonghu, dianpu);
        }
    }

    /**
     * 查询
     *
     * @param yonghu
     */
    public ShanjiaZhxg cx(String yonghu) {
        String username = kaidianmapper.cx(yonghu);
        String password = shanjiamapper.cx(username);
        ShanjiaZhxg shanjiaZhxg = new ShanjiaZhxg();
        if (Objects.equals(username, "") || username == null)
            return null;
        shanjiaZhxg.setPassword(password);
        shanjiaZhxg.setUsername(username);
        return shanjiaZhxg;
    }
}
